package com.third.login;

import android.app.Activity;

import com.third.share.ThirdShareBase;

import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;

/**
 * Created by fzh on 2017/8/1.
 */

public class ThirdLoginFactory {
    public static final int QQ_LOGIN = 1;
    public static final int WEIXI_LOGIN = 2;
    public static final int WEIBO_LOGIN = 3;

    ThirdLoginBase getThridLogin(int style,String clsName, Activity activity,String appKey,String appId){
        ThirdLoginBase thirdLogin = null;
        switch (style){
            case QQ_LOGIN:
                break;
            case WEIXI_LOGIN:
                break;
            case WEIBO_LOGIN:
                break;
        }
        return thirdLogin;
    }

    public static ThirdLoginBase getThridLogin(String clsName, Activity activity,String appKey,String appId)  {
        Object object = null;
        try {
            Class mLoadClass = Class.forName(clsName);
            Constructor constructor = mLoadClass.getConstructor(Activity.class,String.class,String.class);
            object = constructor.newInstance(activity,appKey,appId);
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } catch (NoSuchMethodException e) {
            e.printStackTrace();
        } catch (InstantiationException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (InvocationTargetException e) {
            e.printStackTrace();
        }
        return (ThirdLoginBase)object;
    }

    public static ThirdShareBase getThirdShare(String clsName, Activity activity)  {
        Object object = null;
        try {
            Class mLoadClass = Class.forName(clsName);
            Constructor constructor = mLoadClass.getConstructor(Activity.class);
            object = constructor.newInstance(activity);
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } catch (NoSuchMethodException e) {
            e.printStackTrace();
        } catch (InstantiationException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (InvocationTargetException e) {
            e.printStackTrace();
        }
        return (ThirdShareBase)object;
    }
}
